package com.avhdeveloper.actions;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.SessionAware;

import com.avhdeveloper.utils.Assert;
import com.avhdeveloper.vo.User;
import com.opensymphony.xwork2.ActionSupport;


public class HelloWorld extends ActionSupport implements SessionAware, ServletRequestAware{
  
  /**
   * Definition of HelloWorld.java.
   */
  private static final long serialVersionUID = 1L;
  private String customGreeting;
  private User user;
  private Map<String, Object> session;
  private String role;
  private String title;
  
  public String execute(){
    setCustomGreeting("Hello " + getUser().getName() + "!");
    session.put("time", System.currentTimeMillis());
    return SUCCESS;
  }

  public void setCustomGreeting(String customGreeting) {
    this.customGreeting = customGreeting;
  }

  public String getCustomGreeting() {
    return customGreeting;
  }

  @Override
  public void validate() {
    if (getUser().getName() == null || getUser().getName().length() == 0){
      addFieldError("user.name", getText("name.required"));
    }
  }

  public void setUser(User user) {
    this.user = user;
  }

  public User getUser() {
    return user;
  }

  public void setSession(Map<String,Object> session) {
    Assert.notNull(session);
    this.session = session;
    System.out.println("the session vars were just introduced");
  }

  public void setServletRequest(HttpServletRequest request) {
    Assert.notNull(request);
    System.out.println("the request was just introduced " + request);
  }

  public void setRole(String role) {
    this.role = role;
  }

  public String getRole() {
    return role;
  }

  public void setTitle(String title) {
    this.title = title;
  }

  public String getTitle() {
    return title;
  }

}
